<?php

namespace System\Core;

if (!defined('BASEPATH')) die('Access Denied.');

/**
 * µMVC Framework (c) 2011.
 * 
 * PHP5 MVC Framework software for PHP 5.2.17 or later
 * 
 * @package         µMVC
 * @filename        system/core/controller.class.php
 * @copyright       Lanz (c) 2011.
 * 
 */

class ControllerException extends CommonException {};

/**
 * Controller class
 * Base class for the controllers.
 * 
 * @package         µMVC
 * @subpackage      Core
 * @category        System
 */

abstract class Controller {
       
    function __construct()
    {
        $this->registry = Registry::instance();
        $this->load = Loader::instance();        
        $this->view = View::instance();
        
        Log::instance()->write(Log::DEBUG, 'Controller Class Intitialized');
    }
    
    /**
     * We define the default action as abstract so we get an error message
     * if we forget to include it in the child controller.
     */
    abstract function indexAction();

    /**
     * Magic method just so we can write $this->db instead of having to type
     * $this->registry->db. Yeah I'm a lazy bastard :) 
     */
    public function __get($key)
    {
        if (isset($this->registry->{$key}))
        {
            return $this->registry->{$key};
        }
        else
        {
            throw new ControllerException("$key is not defined in the registry object.");
        }
    }
}

?>
